﻿using CQIE.JonJack.Models.Tabels;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CQIE.JonJack.Models.TabelConfig
{
    public class BookHistoryConfig : IEntityTypeConfiguration<BookHistory>
    {
        public void Configure(EntityTypeBuilder<BookHistory> builder)
        {
            // 设置复合主键
            builder.HasKey(br => new { br.UserId, br.BookId });

            // 配置一对一关系
            builder.HasOne(br => br.User)
                   .WithMany(u => u.BookHistorys)
                   .HasForeignKey(br => br.UserId);

            builder.HasOne(br => br.Book)
                   .WithMany(b => b.BookHistorys)
                   .HasForeignKey(br => br.BookId);
        }
    }
}
